home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Include / GuiIPAddress.au3 < prev    next >
Encoding:
Text File  |  2007-09-08  |  15.6 KB  |  349 lines

  1. #include-once
  2. #include <GUIConstants.au3>
  3. #include <Misc.au3>
  4. ; ------------------------------------------------------------------------------
  5. ;
  6. ; AutoIt Version: 3.2.3++
  7. ; Language:       English
  8. ; Description:    Functions that assist with SysIPAddress32.
  9. ;
  10. ; ------------------------------------------------------------------------------
  11.  
  12. Global Const $WM_SETFONT = 0x30
  13.  
  14. ; font weight
  15. Global Const $FW_DONTCARE = 0
  16. Global Const $FW_THIN = 100
  17. Global Const $FW_EXTRALIGHT = 200
  18. Global Const $FW_ULTRALIGHT = 200
  19. Global Const $FW_LIGHT = 300
  20. Global Const $FW_NORMAL = 400
  21. Global Const $FW_REGULAR = 400
  22. Global Const $FW_MEDIUM = 500
  23. Global Const $FW_SEMIBOLD = 600
  24. Global Const $FW_DEMIBOLD = 600
  25. Global Const $FW_BOLD = 700
  26. Global Const $FW_EXTRABOLD = 800
  27. Global Const $FW_ULTRABOLD = 800
  28. Global Const $FW_HEAVY = 900
  29. Global Const $FW_BLACK = 900
  30.  
  31. ;~ lfItalic
  32. ;~ Specifies an italic font if set to TRUE.
  33. ;~ lfUnderline
  34. ;~ Specifies an underlined font if set to TRUE.
  35. ;~ lfStrikeOut
  36. ;~ Specifies a strikeout font if set to TRUE.
  37.  
  38. Global Const $PROOF_QUALITY = 2
  39.  
  40. Global Const $IPM_CLEARADDRESS = ($WM_USER + 100)
  41. Global Const $IPM_SETADDRESS = ($WM_USER + 101)
  42. Global Const $IPM_GETADDRESS = ($WM_USER + 102)
  43. Global Const $IPM_SETRANGE = ($WM_USER + 103)
  44. Global Const $IPM_SETFOCUS = ($WM_USER + 104)
  45. Global Const $IPM_ISBLANK = ($WM_USER + 105)
  46.  
  47. Global Const $IPN_FIRST = (-860)
  48. Global Const $IPN_FIELDCHANGED = ($IPN_FIRST - 0)
  49.  
  50. Global Const $ICC_INTERNET_CLASSES = 0x800
  51.  
  52. ;===============================================================================
  53. ;
  54. ; Function Name:        _GUICtrlIpAddressCreate
  55. ; Description::        Create a GUI IP Address Control
  56. ; Parameter(s):        hwnd        - handle to a gui window
  57. ;                            left        - The left side of the control
  58. ;                            top        - The top of the control
  59. ;                            width        - The width of the control
  60. ;                            height    - The height of the control
  61. ;                            style        - [optional] defines the style of the control
  62. ;                                        default (-1): none
  63. ;                                        forced styles : $WS_CHILD, $WS_VISIBLE, $WS_TABSTOP
  64. ;                            exstyles    - [optional] Defines the extended style of the control
  65. ;                                        default (-1): none
  66. ; Requirement(s):        none
  67. ; Return Value(s):    handle to the control
  68. ; User CallTip:        _GUICtrlIpAddressCreate(hwnd, left, top, width, height[, style[, exstyles]]) Create a GUI IP Address Control (required: <GuiIPAddress.au3>)
  69. ; Author(s):            Gary Frost (custompcs@charter.net)
  70. ; Note(s):
  71. ;
  72. ;===============================================================================
  73. ;
  74. Func _GUICtrlIpAddressCreate($h_Gui, $i_x, $i_y, $i_width, $i_heigth, $v_styles = -1, $v_exstyles = -1)
  75.     Local $h_IPAddress, $style
  76.     If $v_exstyles = -1 Then $v_exstyles = 0
  77.     If Not IsHWnd($h_Gui) Then $h_Gui = HWnd($h_Gui)
  78.     $style = BitOR($WS_CHILD, $WS_VISIBLE, $WS_TABSTOP)
  79.     If $v_styles <> -1 Then $style = BitOR($style, $v_styles)
  80.     Local $stICCE = DllStructCreate('dword;dword')
  81.     DllStructSetData($stICCE, 1, DllStructGetSize($stICCE))
  82.     DllStructSetData($stICCE, 2, $ICC_INTERNET_CLASSES)
  83.     DllCall('comctl32.dll', 'int', 'InitCommonControlsEx', 'ptr', DllStructGetPtr($stICCE))
  84.     
  85.     $h_IPAddress = DllCall("user32.dll", "long", "CreateWindowEx", "long", $v_exstyles, _
  86.             "str", "SysIPAddress32", "str", "", _
  87.             "long", $style, "long", $i_x, "long", $i_y, "long", $i_width, "long", $i_heigth, _
  88.             "hwnd", $h_Gui, "long", 0, "hwnd", $h_Gui, "long", 0)
  89.     
  90.     If Not @error Then
  91.         Return HWnd($h_IPAddress[0])
  92.     Else
  93.         SetError(1)
  94.     EndIf
  95.     
  96.     Return 0
  97. EndFunc   ;==>_GUICtrlIpAddressCreate
  98.  
  99. ;===============================================================================
  100. ;
  101. ; Function Name:        _GUICtrlIpAddressClear
  102. ; Description::        Clears the contents of the IP address control
  103. ; Parameter(s):        hwnd        - handle to a GUI IP Address control
  104. ; Requirement(s):        none
  105. ; Return Value(s):    none
  106. ; User CallTip:        _GUICtrlIpAddressClear(hwnd) Clears the contents of the IP address control (required: <GuiIPAddress.au3>)
  107. ; Author(s):            Gary Frost (custompcs@charter.net)
  108. ; Note(s):
  109. ;
  110. ;===============================================================================
  111. ;
  112. Func _GUICtrlIpAddressClear($h_IPAddress)
  113.     If Not IsHWnd($h_IPAddress) Then $h_IPAddress = HWnd($h_IPAddress)
  114.     If Not _IsClassName ($h_IPAddress, "SysIPAddress32") Then Return SetError(-1, -1, 0)
  115.     _SendMessage($h_IPAddress, $IPM_CLEARADDRESS)
  116. EndFunc   ;==>_GUICtrlIpAddressClear
  117.  
  118. ;===============================================================================
  119. ;
  120. ; Description:       _GUICtrlIpAddressDelete
  121. ; Parameter(s):      hwnd    -    Handle to statusbar
  122. ; Requirement:
  123. ; Return Value(s):   If the function succeeds, the return value is nonzero
  124. ;                    If the function fails, the return value is zero
  125. ; User CallTip:      _GUICtrlIpAddressDelete(hwnd) Deletes the IpAddress control. (required: <GuiIPAddress.au3>)
  126. ; Author(s):         gafrost (Gary Frost (custompcs at charter dot net))
  127. ; Note(s):
  128. ;===============================================================================
  129. Func _GUICtrlIpAddressDelete($h_IPAddress)
  130.     If Not IsHWnd($h_IPAddress) Then $h_IPAddress = HWnd($h_IPAddress)
  131.     If Not _IsClassName ($h_IPAddress, "SysIPAddress32") Then Return SetError(-1, -1, 0)
  132.     Local $v_ret = DllCall("user32.dll", "int", "DestroyWindow", "hwnd", HWnd($h_IPAddress))
  133.     If Not @error Then Return $v_ret
  134.     Return SetError(1, 1, 0)
  135. EndFunc   ;==>_GUICtrlIpAddressDelete
  136.  
  137. ;===============================================================================
  138. ;
  139. ; Function Name:        _GUICtrlIpAddressGet
  140. ; Description::        Retrieves the address values for all four fields in the IP address control
  141. ; Parameter(s):        hwnd        - handle to a GUI IP Address control
  142. ; Requirement(s):        none
  143. ; Return Value(s):    string containing the ip address from the control
  144. ; User CallTip:        _GUICtrlIpAddressGet(hwnd) Retrieves the address values for all four fields in the IP address control (required: <GuiIPAddress.au3>)
  145. ; Author(s):            Gary Frost (custompcs@charter.net)
  146. ; Note(s):
  147. ;
  148. ;===============================================================================
  149. Func _GUICtrlIpAddressGet($h_IPAddress)
  150.     If Not IsHWnd($h_IPAddress) Then $h_IPAddress = HWnd($h_IPAddress)
  151.     If Not _IsClassName ($h_IPAddress, "SysIPAddress32") Then Return SetError(-1, -1, "")
  152.     Local $dwIP, $ret
  153.     $dwIP = DllStructCreate("ubyte;ubyte;ubyte;ubyte")
  154.     If @error Then Return SetError(1, 1, "")
  155.     _SendMessage($h_IPAddress, $IPM_GETADDRESS, 0, DllStructGetPtr($dwIP), 0, "int", "ptr")
  156.     If @error Then Return SetError(2, 2, "")
  157.     $ret = StringFormat("%d.%d.%d.%d", DllStructGetData($dwIP, 4), _
  158.             DllStructGetData($dwIP, 3), _
  159.             DllStructGetData($dwIP, 2), _
  160.             DllStructGetData($dwIP, 1))
  161.     Return $ret
  162. EndFunc   ;==>_GUICtrlIpAddressGet
  163.  
  164. ;===============================================================================
  165. ;
  166. ; Function Name:        _GUICtrlIpAddressIsBlank
  167. ; Description::        Determines if all fields in the IP address control are blank
  168. ; Parameter(s):        hwnd        - handle to a GUI IP Address control
  169. ; Requirement(s):        none
  170. ; Return Value(s):    Returns nonzero if all fields are blank, or zero otherwise
  171. ; User CallTip:        _GUICtrlIpAddressIsBlank(hwnd) Determines if all fields in the IP address control are blank (required: <GuiIPAddress.au3>)
  172. ; Author(s):            Gary Frost (custompcs@charter.net)
  173. ; Note(s):
  174. ;
  175. ;===============================================================================
  176. ;
  177. Func _GUICtrlIpAddressIsBlank($h_IPAddress)
  178.     If Not IsHWnd($h_IPAddress) Then $h_IPAddress = HWnd($h_IPAddress)
  179.     If Not _IsClassName ($h_IPAddress, "SysIPAddress32") Then Return SetError(-1, -1, 0)
  180.     Local $lResult = _SendMessage($h_IPAddress, $IPM_ISBLANK)
  181.     If Not @error Then
  182.         Return $lResult
  183.     Else
  184.         Return SetError(1, 1, 0)
  185.     EndIf
  186. EndFunc   ;==>_GUICtrlIpAddressIsBlank
  187.  
  188. ;===============================================================================
  189. ;
  190. ; Function Name:        _GUICtrlIpAddressSet
  191. ; Description::        Sets the address values for all four fields in the IP address control
  192. ; Parameter(s):        hwnd        - handle to a GUI IP Address control
  193. ;                            ip            - string containing new ip address for the control
  194. ; Requirement(s):        none
  195. ; Return Value(s):    none
  196. ; User CallTip:        _GUICtrlIpAddressSet(hwnd, ip) Sets the address values for all four fields in the IP address control (required: <GuiIPAddress.au3>)
  197. ; Author(s):            Gary Frost (custompcs@charter.net)
  198. ; Note(s):
  199. ;
  200. ;===============================================================================
  201. ;
  202. Func _GUICtrlIpAddressSet($h_IPAddress, $s_address)
  203.     If Not IsHWnd($h_IPAddress) Then $h_IPAddress = HWnd($h_IPAddress)
  204.     If Not _IsClassName ($h_IPAddress, "SysIPAddress32") Then Return SetError(-1, -1, 0)
  205.     Local $a_address = StringSplit($s_address, ".")
  206.     If $a_address[0] = 4 Then _SendMessage($h_IPAddress, $IPM_SETADDRESS, 0, _MakeIP(_MakeWord($a_address[4], $a_address[3]), _MakeWord($a_address[2], $a_address[1])))
  207. EndFunc   ;==>_GUICtrlIpAddressSet
  208.  
  209. ;===============================================================================
  210. ;
  211. ; Function Name:        _GUICtrlIpAddressSetFocus
  212. ; Description::        Sets the keyboard focus to the specified field in the IP address control.
  213. ;                            All of the text in that field will be selected.
  214. ; Parameter(s):        hwnd        - handle to a GUI IP Address control
  215. ;                            field        - Zero-based field index to which the focus should be set.
  216. ;                                        - If this value is greater than the number of fields,
  217. ;                                        - focus is set to the first blank field. If all fields are nonblank,
  218. ;                                        - focus is set to the first field.
  219. ; Requirement(s):        none
  220. ; Return Value(s):    none
  221. ; User CallTip:        _GUICtrlIpAddressSetFocus(hwnd, field) Sets the keyboard focus to the specified field in the IP address control (required: <GuiIPAddress.au3>)
  222. ; Author(s):            Gary Frost (custompcs@charter.net)
  223. ; Note(s):
  224. ;
  225. ;===============================================================================
  226. ;
  227. Func _GUICtrlIpAddressSetFocus($h_IPAddress, $i_index)
  228.     If Not IsHWnd($h_IPAddress) Then $h_IPAddress = HWnd($h_IPAddress)
  229.     If Not _IsClassName ($h_IPAddress, "SysIPAddress32") Then Return SetError(-1, -1, 0)
  230.     _SendMessage($h_IPAddress, $IPM_SETFOCUS, $i_index)
  231. EndFunc   ;==>_GUICtrlIpAddressSetFocus
  232.  
  233. ;===============================================================================
  234. ;
  235. ; Function Name:        _GUICtrlIpAddressSetRange
  236. ; Description::        Sets the valid range for the specified field in the IP address control
  237. ; Parameter(s):        hwnd        - handle to a GUI IP Address control
  238. ;                            field        - Zero-based field index to which the range will be applied
  239. ;                            low        - [optional] value that contains the lower limit of the range
  240. ;                                        default (0)
  241. ;                            high        - [optional] value that contains the upper limit of the range
  242. ;                                        default (255)
  243. ; Requirement(s):        none
  244. ; Return Value(s):    Returns nonzero if successful, or zero otherwise
  245. ; User CallTip:        _GUICtrlIpAddressSetRange(hwnd, field[, low[, high]]) Sets the valid range for the specified field in the IP address control (required: <GuiIPAddress.au3>)
  246. ; Author(s):            Gary Frost (custompcs@charter.net)
  247. ; Note(s):
  248. ;
  249. ;===============================================================================
  250. ;
  251. Func _GUICtrlIpAddressSetRange($h_IPAddress, $i_index, $i_low_range = 0, $i_high_range = 255)
  252.     If Not IsHWnd($h_IPAddress) Then $h_IPAddress = HWnd($h_IPAddress)
  253.     If Not _IsClassName ($h_IPAddress, "SysIPAddress32") Then Return SetError(-1, -1, 0)
  254.     If $i_low_range < 0 Or $i_low_range > $i_high_range Then
  255.         Return SetError(1, 1, 0)
  256.     ElseIf $i_high_range > 255 Then
  257.         Return SetError(2, 2, 0)
  258.     ElseIf $i_index < 0 Or $i_index > 3 Then
  259.         Return SetError(3, 3, 0)
  260.     EndIf
  261.     Local $lResult = _SendMessage($h_IPAddress, $IPM_SETRANGE, $i_index, _MakeWord($i_low_range, $i_high_range))
  262.     If Not @error Then
  263.         Return $lResult
  264.     Else
  265.         Return SetError(4, 4, 0)
  266.     EndIf
  267. EndFunc   ;==>_GUICtrlIpAddressSetRange
  268.  
  269. ;===============================================================================
  270. ;
  271. ; Function Name:        _GUICtrlIpAddressShowHide
  272. ; Description::        Shows/Hides the IP address control
  273. ; Parameter(s):        hwnd        - handle to a GUI IP Address control
  274. ;                            state        - @SW_SHOW/@SW_HIDE
  275. ; Requirement(s):        none
  276. ; Return Value(s):    If the control was previously visible, the return value is nonzero.
  277. ;                            If the control was previously hidden, the return value is zero.
  278. ; User CallTip:        _GUICtrlIpAddressShowHide(hwnd, state) Sets the IP address control show state (required: <GuiIPAddress.au3>)
  279. ; Author(s):            Gary Frost (custompcs@charter.net)
  280. ; Note(s):
  281. ;
  282. ;===============================================================================
  283. ;
  284. Func _GUICtrlIpAddressShowHide($h_IPAddress, $i_state)
  285.     If Not IsHWnd($h_IPAddress) Then $h_IPAddress = HWnd($h_IPAddress)
  286.     If Not _IsClassName ($h_IPAddress, "SysIPAddress32") Then Return SetError(-1, -1, 0)
  287.     If $i_state <> @SW_HIDE And $i_state <> @SW_SHOW Then Return SetError(1, 1, 0)
  288.     Local $v_ret = DllCall("user32.dll", "int", "ShowWindow", "hwnd", $h_IPAddress, "int", $i_state)
  289.     If Not @error And IsArray($v_ret) Then Return $v_ret[0]
  290.     Return SetError(2, 2, 0)
  291. EndFunc   ;==>_GUICtrlIpAddressShowHide
  292.  
  293. ;===============================================================================
  294. ;
  295. ; Function Name:        _GUICtrlIpAddressSetFont
  296. ; Description::        Set the font for the control
  297. ; Parameter(s):        hwnd        - handle to a GUI IP Address control
  298. ;                            Name        - Optional: The Font Name of the font to use (Default: Arial)
  299. ;                            Size        - Optional: The Font Size (Default: 10)
  300. ;                            Weight    - Optional: The Font Weight (Default: 400 = normal)
  301. ;                            Italic    - Optional: Use Italic Attribute (Default: False)
  302. ; Requirement(s):        none
  303. ; Return Value(s):    None
  304. ;                            If the control was previously hidden, the return value is zero.
  305. ; User CallTip:        _GUICtrlIpAddressSetFont(hwnd [, Name = "Arial"[, Size = 10[, Weight = 400[, Italic = False]]]]) Sets the Font for the IP address control (required: <GuiIPAddress.au3>)
  306. ; Author(s):            Gary Frost (custompcs@charter.net)
  307. ; Note(s):
  308. ;
  309. ;===============================================================================
  310. ;
  311. Func _GUICtrlIpAddressSetFont($h_IPAddress, $FontName = "Arial", $FontSize = 10, $FontWeight = 400, $FontItalic = False)
  312.     If Not IsHWnd($h_IPAddress) Then $h_IPAddress = HWnd($h_IPAddress)
  313.     If Not _IsClassName ($h_IPAddress, "SysIPAddress32") Then Return SetError(-1, -1, 0)
  314.     Local $ret = DllCall("gdi32.dll", "long", "GetDeviceCaps", "long", 0, "long", $LOGPIXELSX)
  315.     If ($ret[0] == -1) Then Return SetError(3, 3, 5)
  316.     Local $lfHeight = Round(($FontSize * $ret[2]) / 72, 0)
  317.     Local $font = DllStructCreate("int;int;int;int;int;byte;byte;byte;byte;byte;byte;byte;byte;char[32]")
  318.     DllStructSetData($font, 1, $lfHeight + 1)
  319.     DllStructSetData($font, 5, $FontWeight)
  320.     DllStructSetData($font, 6, $FontItalic)
  321.     DllStructSetData($font, 7, False) ; font underline
  322.     DllStructSetData($font, 8, False) ; font strikethru
  323.     DllStructSetData($font, 12, $PROOF_QUALITY)
  324.     DllStructSetData($font, 14, $FontName)
  325.     $ret = DllCall("gdi32.dll", "long", "CreateFontIndirect", "long", DllStructGetPtr($font))
  326.     If IsArray($ret) And Not @error Then
  327.         If $ret[0] Then _SendMessage($h_IPAddress, $WM_SETFONT, $ret[0], True, 0, "long", "int")
  328.     EndIf
  329.     
  330. EndFunc   ;==>_GUICtrlIpAddressSetFont
  331.  
  332. ;===============================================================================
  333. ; the following functions are for internal use
  334. ;===============================================================================
  335. Func _HiWord($x)
  336.     Return BitShift($x, 16)
  337. EndFunc   ;==>_HiWord
  338.  
  339. Func _LoWord($x)
  340.     Return BitAND($x, 0xFFFF)
  341. EndFunc   ;==>_LoWord
  342.  
  343. Func _MakeIP($HiWord, $LoWord)
  344.     Return BitOR($LoWord * 0x10000, BitAND($HiWord, 0xFFFF))
  345. EndFunc   ;==>_MakeIP
  346.  
  347. Func _MakeWord($LoByte, $HiByte)
  348.     Return BitOR($LoByte, 0x100 * $HiByte)
  349. EndFunc   ;==>_MakeWord